package logic

import (
	"context"
	user2 "gozeroProject/rpc/pb/user"

	"gozeroProject/api/internal/svc"
	"gozeroProject/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
	return &CreateUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateUserLogic) CreateUser(req *types.AddUserRequest) (*types.AddUserResponse, error) {

	user := user2.AddUserReq{
		UserId:   req.UserId,
		Name:     req.Name,
		Mobile:   req.Mobile,
		Gender:   req.Gender,
		Nickname: req.Nickname,
		Type:     int32(req.Type),
	}
	_, err := l.svcCtx.UserRpc.AddUser(l.ctx, &user)
	if err != nil {
		return nil, err
	}

	return &types.AddUserResponse{Success: "数据插入成功！"}, nil
}
